
/**
 * Created by Administrator on 2016/11/10.
 */
(function(){
    var message={
        init:function(){
            this.deleteLi();
            this.clearAll();
            this.addContent();
        },
        deleteLi:function(){ /*删除*/
            $(".my_message_list").on("click",".mes_det",function(){
                var id=$(this).closest("li").data("id");
                var type = $(this).closest("ul").data("type");
                $.post(get_userUrl()+'Cmessage/delete',{id:id, type:type},function(json){ 
                    if(json.status){ 
                    	layer.msg(json.errmsg, {icon:1,time:1000}, function(){
                    		window.location.href = json.data;
                    	});
                    }else{ 
                        layer.msg(json.errmsg, {icon:2,time:1000});
                        return false;
                    }
                }, "json");
            });
        },
        clearAll:function(){/*清空所有*/
            $(".mes_clear").on("click",function(){
                $.post(get_userUrl()+'Cmessage/delete_all',{all:1},function(json){
                    if(json.status){
                    	layer.msg(json.errmsg,{icon:1,time:1000}, function(){
                    		window.location.href = json.data;
                    	});
                    }else{
                    	layer.msg(json.errmsg,{icon:2,time:1000});
                        return false;
                    }
                }, "json");
            })
        },
        addContent:function(){/*展开收缩*/
            $(".my_notice").find(".my_notice_con").each(function(index){
               var txt=$(".my_notice_con").eq(index).data("title");
                if(txt.length>=100){
                    $(".my_notice_con").eq(index).html(txt.substr(0,100)).append('<span class="down"> [展开]</span>');
                }else{
                    $(".my_notice_con").eq(index).text(txt);
                }
            });

            $(".my_notice_con").on("click","span.down",function(){
                $(this).parent().text($(this).parent().data("title")).append('<span class="up"> [收缩]</span>');
            });
            $(".my_notice_con").on("click","span.up",function(){
                $(this).parent().text($(this).parent().data("title").substr(0,100)).append('<span class="down"> [展开]</span>');
            });

        }
    };
    message.init();
})();